package test

import config.MyFile
import org.apache.commons.io.FileUtils
import scala.jdk.CollectionConverters._

object test5 extends MyFile {

  def main(args: Array[String]): Unit = {

    val lineMap = "D:\\喜树碱植物基因组数据库网站\\block\\Collinear/cac_2021_vs_cac_2017.collinearity".readLines.filter(!_.startsWith("#")).map(_.split("\t")).map { x =>
      x(1) -> x(2)
    }.groupBy(_._1).map { x => x._1 -> x._2.map(_._2) }

    val cac2017 = "D:\\喜树碱植物基因组数据库网站/fpkm_2017.txt".readLines.tail.map(_.split("\t")).map(x=> x.head -> x.tail).toMap

    val lines = "D:\\喜树碱植物基因组数据库网站/fpkm.txt".readLines

    val row = lines.tail.map(_.split("\t")).filter(x=> lineMap.get(x.head).nonEmpty).map { x =>
      val cac_2017 = lineMap(x.head).map{y=>
        cac2017(y)
      }.maxBy(y=>y.map(_.toDouble).sum)
      x ++ cac_2017
    }.filter(x=> x.tail.map(_.toDouble).sum > 10).map(_.mkString("\t"))

    FileUtils.writeLines("D:\\喜树碱植物基因组数据库网站/fpkm_filter.txt".toFile, row.asJava)

  }

  def xx = {
    val lines = "D:\\喜树碱植物基因组数据库网站/fpkm.txt".readLines

    val l = lines.tail.filter { x =>
      x.split("\t").tail.map(_.toDouble).sum >= 10.0
    }

    FileUtils.writeLines("D:\\喜树碱植物基因组数据库网站/fpkm_filter.txt".toFile, (lines.head +: l).asJava)

  }
}
